/**
 * Created by caosh on 2018/5/14 0014.
 */
var bankCard = new Vue({
    el: '#bank-card',
    data: {
        acctInfo: null,
        show: '',
        card: {},
        bankList: [],
        isPersonal: true,
        cardAuth: {}
    },
    methods: {
        getAcctInfo: function () {
            var _this = this;
            _this.setAjaxOptions('/getAcctInfo', {'acctId': _this.userinfo.loginName}, function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    _this.acctInfo = result.data;
                } else {
                    console.log(result.errMsg);
                }
            });

            // _this.doAjax();
        },
        getBankList: function () {
            var _this = this;
            _this.setAjaxOptions('/getBankList', null, function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    _this.bankList = result.data;
                } else {
                    console.log(result.errMsg);
                }
            });
            _this.doAjax();
        },
        openBindCard: function () {
            this.show = 'bindAccount';
            Vue.useLayerForm();
        },
        bindCard: function () {
            var _this = this;
            _this.setAjaxOptions('/bindCard', _this.card, function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    console.log('绑定成功！');
                } else {
                    console.log(result.errMsg);
                }
            });
            _this.doAjax();
        },
        resetCard: function (type) {
            this.card = {
                'user': '',
                'type': type,
                'name': '',
                'idNumber': '',
                'sBankCode': '',
                'bankName': '',
                'bankNumber': '',
                'phone': ''
            }

            this.cardAuth = {
                'user': '',
                'type': type,
                'checkCode': ''
            }
        },
        bindCardAuth: function () {
            var _this = this;
            _this.setAjaxOptions('/bindCardAuth', _this.cardAuth, function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    console.log('验证通过！');
                } else {
                    console.log(result.errMsg);
                }
            });
            _this.doAjax();
        }
    },
    mixins: [AjaxMixin, StatusMixin, UserMixin],
    mounted: function () {
        Vue.useLayerElement();
        this.getAcctInfo();
        this.getBankList();
        this.resetCard(0);
    },
    watch: {
        'isPersonal': function (val, oldVal) {
            if (val) {
                this.resetCard(0);
            } else {
                this.resetCard(1);
            }
        }
    }
});